package com.shou.zhnfyxt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shou.zhnfyxt.Dto.HotSearch;
import com.shou.zhnfyxt.entity.R;
import com.shou.zhnfyxt.entity.Region;
import com.shou.zhnfyxt.mapper.RegionDao;
import com.shou.zhnfyxt.service.IRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author JCY
 * @since 2022-12-27
 */
@Service
public class RegionServiceImpl extends ServiceImpl<RegionDao, Region> implements IRegionService {
@Autowired
private IRegionService regionService;
    @Override
    public R<List<HotSearch>> search(String houseSearch) {
        System.out.println(houseSearch);
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("level", 2);
        queryWrapper.like("sname", houseSearch);
        List<Region> regionList = regionService.list(queryWrapper);
        System.out.println(regionList);
        List<String> collect = regionList.stream().map(Region::getSname).collect(Collectors.toList());
        ArrayList<HotSearch> list = new ArrayList<>();
        for (String s : collect) {
            HotSearch hotSearch = new HotSearch(s);
            list.add(hotSearch);
        }
        return R.success(list);
    }
}
